package com.ruoyi.web.controller.pv;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pv.domain.PvRoom;
import com.ruoyi.pv.service.IPvRoomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 场地管理Controller
 *
 * @author zzx
 * @date 2023-03-12
 */
@Api("场地管理")
@RestController
@RequestMapping("/pv/room")
public class PvRoomController extends BaseController {
    @Autowired
    private IPvRoomService pvRoomService;

    /**
     * 查询场地管理列表
     */

    @GetMapping("/list")
    @ApiOperation("查询场地管理列表")
    public TableDataInfo list(PvRoom pvRoom) {
        pvRoom.setReservedOne(getDeptId());
        startPage();
        List<PvRoom> list = pvRoomService.selectPvRoomList(pvRoom);
        return getDataTable(list);
    }

    /**
     * 导出场地管理列表
     */
    @PreAuthorize("@ss.hasPermi('pv:room:export')")
    @Log(title = "场地管理" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PvRoom pvRoom) {
        pvRoom.setReservedOne(getDeptId());
        List<PvRoom> list = pvRoomService.selectPvRoomList(pvRoom);
        ExcelUtil<PvRoom> util = new ExcelUtil<PvRoom>(PvRoom.class);
        util.exportExcel(response, list, "场地管理数据");
    }

    /**
     * 获取场地管理详细信息
     */

    @GetMapping(value = "/{id}")
    @ApiOperation("获取场地管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pvRoomService.selectPvRoomById(id));
    }

    /**
     * 新增场地管理
     */
    @PreAuthorize("@ss.hasPermi('pv:room:add')")
    @Log(title = "场地管理" , businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增场地管理")
    public AjaxResult add(@RequestBody PvRoom pvRoom) {
        pvRoom.setReservedOne(getDeptId());
        return toAjax(pvRoomService.insertPvRoom(pvRoom));
    }

    /**
     * 修改场地管理
     */
    @PreAuthorize("@ss.hasPermi('pv:room:edit')")
    @Log(title = "场地管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改场地管理")
    public AjaxResult edit(@RequestBody PvRoom pvRoom) {
        return toAjax(pvRoomService.updatePvRoom(pvRoom));
    }

    /**
     * 删除场地管理
     */
    @PreAuthorize("@ss.hasPermi('pv:room:remove')")
    @Log(title = "场地管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除场地管理")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pvRoomService.deletePvRoomByIds(ids));
    }
}
